
function trim(val) { 
	 
	return val.replace(/(^\s*)|(\s*$)/g, "");  
	
} 

function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}


 

function searchForm(){
	
		 
	document.indexForm .submit();
	
}

function delIndexInfo(){
	var listsize = document.getElementById('listsize').value;
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	if(pkid_string == ''){
		alert('请至少选择一条!');
		return false;
	}
	document.getElementById('pkid').value = pkid_string;
	document.indexForm.action='/doTradeReg.do';
	if(window.confirm('确认删除吗?')){
		document.indexForm.submit();
	}
}

function delOneNews(val){
	 
    if(window.confirm('确认删除吗?'))
    {
   	  window.location.href='/doTradeReg.do?pkid='+val+'&bpm_id=8260'; 
    } 		
	
}

function isMaxLen(o)
{  
	 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";  
	 if(o.getAttribute && o.value.length>nMaxLen)
	 {      
	 	  o.value=o.value.substring(0,nMaxLen);  
	 }  
}

function updateStock()
{
  if(trim(document.getElementById("one_price").value)=="")
  {
    alert("请输入商品库存单价！");
    return;  
  }
  if(trim(document.getElementById("now_num").value)=="")
  {
    alert("请输入现有库存量！");
    return;  
  }
  
  var now_num = document.getElementById("now_num").value;
                                                      
  var before_num = document.getElementById("before_num").value;                                                       
  
  if(trim(document.getElementById("vary_reason").value)=="")
  {														//fixed by Zhouxq
    alert("请输入异动原因！");
    document.getElementById("vary_reason").focus();
    return;  
  }
  
  document.getElementById("vary_num").value = parseInt(now_num) - parseInt(before_num); 
                                                                                       
  document.getElementById("stock_num").value = now_num;                                                                                     
                                                                                       
  document.addForm.submit();

} 

function showDiv(val)
{
  var data = Math.round(Math.random()* 10000);  
 
  var rURL = "/program/admin/stock/varReason.jsp?height=200&width=400&trade_id="+val+"&date="+data;
 
  TB_show('',rURL,false);
} 